//
//  MyWorksCommonCell.m
//  WeiWeiHaircut
//
//  Created by 超群 on 15/10/16.
//  Copyright © 2015年 超群. All rights reserved.
//

#import "MyWorksCommonCell.h"
#import "UIView+RoundView.h"
#import "PhotoBroswerVC.h"
#import "WorkModel.h"
#import "ImageListModel.h"
#import "QZDateManager.h"
@interface MyWorksCommonCell()
@property (nonatomic,strong) NSArray *images;//图片数组
@end
@implementation MyWorksCommonCell

- (void)awakeFromNib {

//    [self.contentView setlineFrame:CGRectMake(0, 0.5f, WIDTH, .5f) lineColor:groupDarkGrayColor lineAlpha:1];
//    [self.contentView setlineFrame:CGRectMake(0, 233.5f, WIDTH, .5f) lineColor:groupDarkGrayColor lineAlpha:1];
    
    [self.supportBtn addTarget:self action:@selector(likeClikc:) forControlEvents:UIControlEventTouchUpInside];

}
-(void)likeClikc:(UIButton *)btn{
    if (self.myBlock) {
         _myBlock(btn);
    }
   
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

// 获取网络图片
-(void)networkImageShow:(NSUInteger)index{
    __weak typeof(self) weakSelf=self;
    
    [PhotoBroswerVC show:_controller type:PhotoBroswerVCTypeZoom index:index photoModelBlock:^NSArray *{
        
        
        NSArray *networkImages= weakSelf.images;
        
        NSMutableArray *modelsM = [NSMutableArray arrayWithCapacity:networkImages.count];
        for (NSUInteger i = 0; i< networkImages.count; i++) {
            
            PhotoModel *pbModel=[[PhotoModel alloc] init];
            pbModel.mid = i + 1;

            pbModel.image_HD_U = networkImages[i];
            
            //源frame
            UIImageView *imageV =(UIImageView *) weakSelf.workImageView.subviews[i];
            pbModel.sourceImageView = imageV;
            
            [modelsM addObject:pbModel];
        }
        
        return modelsM;
    }];
    
}

-(NSArray *)images{
    
    if(_images ==nil){
        NSMutableArray *arrayM = [NSMutableArray array];
        
        for (NSUInteger i=0; i<_model.img_list.count; i++) {

            ImageListModel *imageInfo = self.model.img_list[i];
            NSString *url = imageInfo.imgPath;
            [arrayM addObject:url];
        }
        
        _images = arrayM;
    }
    
    return _images;
}
-(void)setModel:(WorkModel *)model{
    _model = model;
    
    self.workNameLabel.text = model.hairFormDepict;
    self.surpportNumLabel.text = [NSString stringWithFormat:@"%ld",model.people];
    NSString *time = [[QZDateManager sharedDateManager] secondToStringTIme:model.time];
    self.timeLabel.text = time;
    if (self.model.is_people) {
        [self.supportBtn setImage:[UIImage imageNamed:@"喜欢-图标-选中"] forState:UIControlStateNormal];
    }else{
        [self.supportBtn setImage:[UIImage imageNamed:@"形状-2"] forState:UIControlStateNormal];
    }
    
    __weak typeof(self) weakSelf = self;
    self.images = nil;
    [_workImageView setImages:self.images];
    
    _workImageView.ClickImageBlock = ^(NSUInteger index){
        
        [weakSelf networkImageShow:index];
    };
    
}


@end
